import Cupk2Request from "@/service/remoteRequests/Cupk2Request";
import type { Router } from "vue-router";

/**
 * 获取html中由H1H2H3组成的标题
 * @param html - 大段的HTML字符串
 * @returns 包含标题名称、标签、层级和顺序号的数组
 */
const openPageByPathId = (path: string, id: string, type: string) => {
  window.open(path + "/" + id, type == "_blank" ? "_blank" : "_self");
};

/**
 * 文件下载
 * @param fileid
 */
const downloadFile = (id: string) => {
  const url = Cupk2Request.getFullPath("api/files/download/" + id);
  window.open(url, "_blank");
};
/**
 * 返回首页
 */
const goToHome = () => {
  window.open("/home", "_self");
};
/**
 * 跳转到查询页面执行查询
 *
 * import { useRouter } from 'vue-router';
 * const router = useRouter();
 */
const gotoSearchPage = (
  searchword: { word: string; page: number },
  router: Router
) => {
  if (searchword.word.trim()) {
    router.push({ path: "/search", query: { word: searchword.word } });
  }
};

export default { openPageByPathId, downloadFile, goToHome, gotoSearchPage };
